/*******************************************************************************
 *
 * Copyright (c) 2008-2011 ayound@gmail.com
 * This program and the accompanying materials
 * are made available under the terms of the GNU GENERAL PUBLIC LICENSE
 * which accompanies this distribution, and is available at
 * http://dev.perl.org/licenses/gpl1.html
 * All rights reserved.
 *
 * Created on 2009-11-10
 *******************************************************************************/

package org.ayound.skin.editor.core;

import java.io.File;

import org.ayound.skin.editor.core.convert.IConverter;
import org.ayound.skin.editor.core.convert.image.ImageConverter;
import org.ayound.skin.editor.core.convert.model.SkinModel;
import org.ayound.skin.editor.core.convert.style.StyleConverter;

public class SkinBuilder {
	public static void buildSkin(String skinPath, SkinModel model) {
		File file = new File(skinPath);
		buildSkin(file, model);
	}

	public static void buildSkin(File file, SkinModel model) {
		if (file.isDirectory()) {
			for (File child : file.listFiles()) {
				buildSkin(child, model);
			}
		} else {
			String fileName = file.getName().toLowerCase();
			if (fileName.endsWith(".gif") || fileName.endsWith(".jpg") ||fileName.endsWith(".png")) {
				buildImage(file,model);
			}
			if (fileName.endsWith(".css")) {
				buildStyle(file,model);
			}
		}
	}

	private static void buildStyle(File file, SkinModel model) {
		IConverter converter = new StyleConverter(model);
		converter.convert(file.getAbsolutePath());

	}

	private static void buildImage(File file, SkinModel model) {
		IConverter converter = new ImageConverter(model);
		converter.convert(file.getAbsolutePath());
	}
}

